package com.zkthink.ceres.product.dto;

import java.io.Serializable;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;

import com.zkthink.base.entity.SuperEntity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
import org.springframework.util.CollectionUtils;

/**
 * <p>
 * 实体类
 * 物流运送区域
 * </p>
 *
 * @author vivi.huang
 * @since 2020-05-16
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = false)
@Builder
@ApiModel(value = "LogisticsRegionDTO", description = "物流运送区域")
public class LogisticsRegionDTO implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 1级分割
     */
    private static final String FIRST_LEVER_SPLIT = ":";
    /**
     * 2级分割
     */
    private static final String SECOND_LEVER_SPLIT = ",";

    public LogisticsRegionDTO(String region) {
        String[] arr = region.split(FIRST_LEVER_SPLIT);
        this.province = arr[0];
        if (arr.length > 1) {
            this.cityList = Arrays.stream(arr[1].split(SECOND_LEVER_SPLIT)).collect(Collectors.toList());
        }
    }

    /**
     * 计费明细
     */
    @ApiModelProperty(value = "省份")
    private String province;

    /**
     * 城市
     */
    @ApiModelProperty(value = "城市")
    private List<String> cityList;


    /**
     * 只选省份
     * @return
     */
    public boolean isOnlyProvince() {
        return CollectionUtils.isEmpty(cityList);
    }

    public boolean isMunicipality() {
        return this.province.equals(cityList.get(0));
    }
}
